<?php
/**

 * [Laike System] Copyright (c) 2017-2020 laiketui.com

 * Laike is not a free software, it under the license terms, visited http://www.laiketui.com/ for more details.

 */
require_once(MO_LIB_DIR . '/DBAction.class.php');

class delAction extends Action {

    public function getDefaultView() {
        $db = DBAction::getInstance();
        $request = $this->getContext()->getRequest();
        $admin_id = $this->getContext()->getStorage()->read('admin_id');

        $cat_id = intval($request->getParameter('cat_id')); // 文章分类id

                    
        $sql = "select * from lkt_article where article_class = '$cat_id'";
        $r = $db->select($sql);
        if($r){
            $db->admin_record($admin_id,' 删除文章分类id为 '.$cat_id.' 失败,检查此分类下是否有文章',3);
            echo 2;
            exit;
        }else{
            // 根据分类id,删除这条数据
            $sql = "delete from lkt_article_class where cat_id=$cat_id";
            // echo $sql;
            // var_dump( $cat_id);
            // var_dump(  $sql);


            $res = $db->delete($sql);            
           //  var_dump( $res);
           // die();

            if($res){
                $db->admin_record($admin_id,' 删除文章分类id为 '.$cat_id.' 的信息',3);
                  echo 1;
                exit;
            }else{
                $db->admin_record($admin_id,' 删除文章分类id为 '.$cat_id.' 失败',3);
                echo 0;
                exit;
            };
        }
                    
  
    }



    public function execute(){
        return $this->getDefaultView();
    }

    public function getRequestMethods(){
        return Request :: NONE;
    }
}
?>